package com.hcxy.filetransform.widget;

import java.awt.Color;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.Date;

import javax.swing.JLabel;

public class TextMsgLogView extends JLabel {
	private String text;
	private Date date;
	public TextMsgLogView(final String text,final Date date) {
		this.text = text;
		this.date = date;
		String content = "<html>"+text+"<br>"+date.toLocaleString()+"</html>";
		setText(content);
		setBounds(20, 0, 0, 0);
		setForeground(new Color(255,255,255));
		setAlignmentX(0.8f);
		addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				super.mouseClicked(e);
				if (e.getClickCount()==2) {
					Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
					StringSelection str = new StringSelection(text);
					clipboard.setContents(str, str);
				}else if(e.getClickCount()==3){
					Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
					StringSelection str = new StringSelection(text+System.getProperty("line.separator")+date.toLocaleString());
					clipboard.setContents(str, str);
				}
			}
		});
	}
	
}
